/*****************************************************************
Copyright:      @2023 - 2023
Filename:       SilmLogApi.h
Description:    C/C++ library of write log
Author:         August
Version:        1.0
Datetime:       2023.04.19
******************************************************************/
#ifndef _SILM_LOG_API_H_
#define _SILM_LOG_API_H_

#define SILM_LOG_VERSION_MAJOR 1
#define SILM_LOG_VERSION_MINOR 0

#define SILM_LOG_VERSION(major, minor) (((unsigned int)(major)) << 16 | (minor))
#define SILM_LOG_GETVER_MAJOR(version) (((version) >> 16) & 0xFFFF)
#define SILM_LOG_GETVER_MINOR(version) ((version)&0xFFFF)

#ifdef _WIN32
#define SILMLOG_API __cdecl
#else
#define SILMLOG_API
#endif

#ifndef IN
#define IN
#endif // IN

#ifndef OUT
#define OUT
#endif // OUT

#ifndef INOUT
#define INOUT
#endif // INOUT

#ifndef OPTIONAL
#define OPTIONAL
#endif // OPTIONAL

#define SILM_LOG_INIT_BITMAP_SYS        0x1//write sys log
#define SILM_LOG_INIT_BITMAP_FILE       0x2//write log to file
#define SILM_LOG_INIT_BITMAP_CONSOLE    0x4//write log to console

#define SILM_LOG_TYPE_DEBUG 0
#define SILM_LOG_TYPE_ERROR 1
#define SILM_LOG_TYPE_INFO  2
#define SILM_LOG_TYPE_WARN  3

#ifdef __cplusplus
extern "C"
{
#endif //__cplusplus

    //************************************
    // Function:  SilmLogInit
    // Returns:   return 0 for success, otherwise errno
    // Remark:    thread unsafe, and must invoke only once
    // Description: Initialize for log library
    // Parameter:
    //            unsigned int version: 
    //            unsigned int bitmap: SILM_LOG_INIT_BITMAP_*
    //            const char * pLogFilename: absolute path for log file, can be NULL, except set SILM_LOG_INIT_BITMAP_FILE for bitmap
    //************************************
    int SILMLOG_API SilmLogInit(IN unsigned int version, IN unsigned int bitmap, IN const char *pLogFilename);

    //************************************
    // Function:  SilmLogUnInit
    // Returns:   void
    // Description: Uninitialize for log library
    // Parameter:
    //            void:
    //************************************
    void SILMLOG_API SilmLogUnInit(void);

    //************************************
    // Function:  SilmLogWrite
    // Returns:   return 0 for success, otherwise errno
    // Description: write log
    // Parameter:
    //            IN unsigned int logType: type of log, SILM_LOG_TYPE_*
    //            const char * format: //format like printf
    //            ...: parameter for format
    //************************************
#define SilmLogDbg(fmt, ...)    SilmLogWrite(SILM_LOG_TYPE_DEBUG, fmt, ##__VA_ARGS__)
#define SilmLogInfo(fmt, ...)   SilmLogWrite(SILM_LOG_TYPE_INFO, fmt, ##__VA_ARGS__)
#define SilmLogErr(fmt, ...)    SilmLogWrite(SILM_LOG_TYPE_ERROR, fmt, ##__VA_ARGS__)
#define SilmLogWarn(fmt, ...)   SilmLogWrite(SILM_LOG_TYPE_WARN, fmt, ##__VA_ARGS__)
    int SILMLOG_API SilmLogWrite(IN unsigned int logType, IN const char *format, ...);

#ifdef __cplusplus
};
#endif //__cplusplus

#endif //_SILM_LOG_API_H_
